package com.allen.study.application.api;

import com.allen.study.application.api.request.SysRoleCreateRequest;
import com.allen.study.application.api.request.SysRoleQueryRequest;
import com.allen.study.application.api.request.SysRoleUpdateRequest;
import com.allen.study.application.api.response.SysRoleQueryResponse;
import com.allen.study.application.api.response.SysRoleResponse;
import com.allen.study.application.service.SysRoleAppService;
import com.allen.study.common.base.ApiPageResponse;
import com.allen.study.common.base.ApiResponse;
import com.allen.study.common.base.Pagination;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 角色表接口
 *
 * @author AllenSun
 * @since 2025-04-23 20:46
 */
@RequestMapping(value = "/4.2.0/sysrole")
@RestController
@AllArgsConstructor
@Tag(name = "角色表接口", description = "角色表接口")
public class SysRoleApi {

    /**
     * 角色表应用服务
     */
    private final SysRoleAppService sysRoleAppService;

    /**
     * 创建角色表
     *
     * @param createRequest 角色表创建对象
     * @return 响应结果
     */
    @PostMapping
    @Operation(summary = "创建角色表", description = "创建角色表")
    public ApiResponse<Void> create(@RequestBody @Valid SysRoleCreateRequest createRequest) {
        return sysRoleAppService.create(createRequest);
    }

    /**
     * 根据主键删除角色表
     *
     * @param sysRoleId 角色表主键
     * @return 响应结果
     */
    @DeleteMapping(value = "/{sys_role_id}")
    @Operation(summary = "根据主键删除角色表", description = "根据主键删除角色表")
    public ApiResponse<Void> deleteById(@PathVariable(name = "sys_role_id") String sysRoleId) {
        return sysRoleAppService.deleteById(sysRoleId);
    }

    /**
     * 根据主键更新角色表
     *
     * @param sysRoleId 角色表主键
     * @param updateRequest 角色表更新对象
     * @return 响应结果
     */
    @PutMapping(value = "/{sys_role_id}")
    @Operation(summary = "根据主键更新角色表", description = "根据主键更新角色表")
    public ApiResponse<Void> updateById(@PathVariable(name = "sys_role_id") String sysRoleId,
            @RequestBody @Valid SysRoleUpdateRequest updateRequest) {
        return sysRoleAppService.updateById(sysRoleId, updateRequest);
    }

    /**
     * 根据主键查询角色表详情
     *
     * @param sysRoleId 角色表主键
     * @return 响应结果
     */
    @GetMapping(value = "/{sys_role_id}")
    @Operation(summary = "根据主键查询角色表详情", description = "根据主键查询角色表详情")
    public ApiResponse<SysRoleResponse> queryById(@PathVariable(name = "sys_role_id") String sysRoleId) {
        return sysRoleAppService.queryById(sysRoleId);
    }

    /**
     * 分页查询角色表
     *
     * @param pagination   分页
     * @param queryRequest 角色表查询对象
     * @return 响应结果
     */
    @GetMapping
    @Operation(summary = "分页查询角色表", description = "分页查询角色表")
    public ApiPageResponse<SysRoleQueryResponse> query(@Valid Pagination pagination, @Valid SysRoleQueryRequest queryRequest) {
        return sysRoleAppService.query(pagination, queryRequest);
    }
}
